

clear 
set scheme lean2, permanent
global pm = char(177) 
set more off

gl date = c(current_date)
if c(os) == "MacOSX" gl user "/Users/`c(username)'"
else if c(os) == "Windows" gl user "C:\Users\\`c(username)'"
else if c(os) == "Unix" gl user "/usr/`c(username)'"
di "$user

set graphics on  

global path_data_processed "\data\processed"
global path_output "\data\output"

 
clear all
set more off

cd "$path_data_processed"
use "experimentRNall.dta", clear

cd "$path_output"
 
gen ind_cyclical=1-health_educ-ind_other
tab ind_cyclical, m
gen ind_noncyclical=1-ind_cyclical
 
foreach var of varlist republican democrat finlit_index{
gen mis_`var' = `var'==.
replace `var'=0 if `var'==.
}

replace log_income=0 if inc_NR==1
global controls age agesq female log_income inc_NR atleast_bachelor midwest south west republican democrat finlit_index mis_republican mis_finlit_index
	   
gen updating_educ = updating*atleast_bachelor
gen shock_educ = shock*atleast_bachelor
gen prior_educ = prior*atleast_bachelor

gen updating_old = updating*old
gen shock_old = shock*old
gen prior_old = prior*old

gen updating_female = 	updating*female
gen shock_female = shock*female
gen prior_female = prior*female

gen updating_highearn = updating*highearn
gen shock_highearn = shock*highearn
gen prior_highearn = prior*highearn

gen updating_ever_unemp = updating*ever_unemployed_imp
gen shock_ever_unemp = shock*ever_unemployed_imp
gen prior_ever_unemp = prior*ever_unemployed_imp

gen updating_never_unemp = updating*never_unemployed_imp
gen shock_never_unemp = shock*never_unemployed_imp
gen prior_never_unemp = prior*never_unemployed_imp

gen updating_highcountyunemp = updating*highunemp_rate3y
gen shock_highcountyunemp = shock*highunemp_rate3y
gen prior_highcountyunemp = prior*highunemp_rate3y

gen updating_lowcountyunemp = updating*(1-highunemp_rate3y)
gen shock_lowcountyunemp = shock*(1-highunemp_rate3y)
gen prior_lowcountyunemp = prior*(1-highunemp_rate3y)

gen updating_ind_cyclical = updating*ind_cyclical
gen shock_ind_cyclical = shock*ind_cyclical
gen prior_ind_cyclical = prior*ind_cyclical

gen updating_ind_noncyclical = updating*(1-ind_cyclical)
gen shock_ind_noncyclical = shock*(1-ind_cyclical)
gen prior_ind_noncyclical = prior*(1-ind_cyclical)

gen updating_finlit_index = updating*finlit_index
gen shock_finlit_index = shock*finlit_index
gen prior_finlit_index = prior*finlit_index

gen updating_republican = updating*republican
gen shock_republican = shock*republican
gen prior_republican = prior*republican

reg updating shock shock_republican prior prior_republican $controls, r
reg updating shock shock_educ shock_ind_noncyclical prior prior_educ prior_ind_noncyclical ind_noncyclical $controls, r

 
loc experiments "updating updating updating updating updating updating updating updating"

preserve

clear all
eststo clear
estimates drop _all

set obs 10
qui gen x = 1
qui gen y = 1

loc columns = 0

foreach choice in `experiments' {

    loc ++columns
    qui eststo col`columns': reg x y

}

restore


/* Statistics */

loc colnum = 1
loc colnames ""


***OLS


*** Column 1: Education

reg updating shock shock_educ prior prior_educ $controls, r

sigstar shock, prec(3)
estadd loc thisstat2 = "`r(bstar)'": col`colnum'
estadd loc thisstat3 = "`r(sestar)'": col`colnum'

sigstar shock_educ, prec(3)
estadd loc thisstat5 = "`r(bstar)'": col`colnum'
estadd loc thisstat6 = "`r(sestar)'": col`colnum'

test shock + shock_educ = 0
estadd loc thisstat29 = string(r(p), "%9.3f"): col`colnum'

qui sum updating
estadd loc thisstat31 = r(N): col`colnum'
*estadd loc thisstat29 = string(r2[1,1], "%9.2f"): col`colnum'	

loc ++colnum


*** Column 2: Earnings

reg updating shock shock_highearn prior prior_highearn $controls highearn, r

sigstar shock, prec(3)
estadd loc thisstat2 = "`r(bstar)'": col`colnum'
estadd loc thisstat3 = "`r(sestar)'": col`colnum'

sigstar shock_highearn, prec(3)
estadd loc thisstat8 = "`r(bstar)'": col`colnum'
estadd loc thisstat9 = "`r(sestar)'": col`colnum'

test shock + shock_highearn = 0
estadd loc thisstat29 = string(r(p), "%9.3f"): col`colnum'

qui sum updating
estadd loc thisstat31 = r(N): col`colnum'
*estadd loc thisstat29 = string(r2[1,1], "%9.2f"): col`colnum'	

loc ++colnum


*** Column 3: Age

reg updating shock shock_old prior prior_old $controls old, r

sigstar shock, prec(3)
estadd loc thisstat2 = "`r(bstar)'": col`colnum'
estadd loc thisstat3 = "`r(sestar)'": col`colnum'

sigstar shock_old, prec(3)
estadd loc thisstat11 = "`r(bstar)'": col`colnum'
estadd loc thisstat12 = "`r(sestar)'": col`colnum'

test shock + shock_old = 0
estadd loc thisstat29 = string(r(p), "%9.3f"): col`colnum'

qui sum updating
estadd loc thisstat31 = r(N): col`colnum'
*estadd loc thisstat29 = string(r2[1,1], "%9.2f"): col`colnum'	

loc ++colnum


*** Column 4: Gender

reg updating shock shock_female prior prior_female $controls, r

sigstar shock, prec(3)
estadd loc thisstat2 = "`r(bstar)'": col`colnum'
estadd loc thisstat3 = "`r(sestar)'": col`colnum'

sigstar shock_female, prec(3)
estadd loc thisstat14 = "`r(bstar)'": col`colnum'
estadd loc thisstat15 = "`r(sestar)'": col`colnum'

test shock + shock_female = 0
estadd loc thisstat29 = string(r(p), "%9.3f"): col`colnum'

qui sum updating
estadd loc thisstat31 = r(N): col`colnum'
*estadd loc thisstat29 = string(r2[1,1], "%9.2f"): col`colnum'	

loc ++colnum


*** Column 5: Industry

reg updating shock shock_ind_noncyclical ind_cyclical prior prior_ind_noncyclical $controls, r

sigstar shock, prec(3)
estadd loc thisstat2 = "`r(bstar)'": col`colnum'
estadd loc thisstat3 = "`r(sestar)'": col`colnum'

sigstar shock_ind_noncyclical, prec(3)
estadd loc thisstat17 = "`r(bstar)'": col`colnum'
estadd loc thisstat18 = "`r(sestar)'": col`colnum'

test shock + shock_ind_noncyclical = 0
estadd loc thisstat29 = string(r(p), "%9.3f"): col`colnum'

qui sum updating if ind_cyclical!=.
estadd loc thisstat31 = r(N): col`colnum'
*estadd loc thisstat29 = string(r2[1,1], "%9.2f"): col`colnum'	

loc ++colnum


*** Column 6: Personal unemployment history

reg updating shock shock_never_unemp never_unemployed_imp prior prior_never_unemp $controls, r

sigstar shock, prec(3)
estadd loc thisstat2 = "`r(bstar)'": col`colnum'
estadd loc thisstat3 = "`r(sestar)'": col`colnum'

sigstar shock_never_unemp, prec(3)
estadd loc thisstat20 = "`r(bstar)'": col`colnum'
estadd loc thisstat21 = "`r(sestar)'": col`colnum'
	
test 	shock + shock_never_unemp = 0
estadd loc thisstat29 = string(r(p), "%9.3f"): col`colnum'

qui sum updating if never_unemployed_imp!=.
estadd loc thisstat31 = r(N): col`colnum'
*estadd loc thisstat29 = string(r2[1,1], "%9.2f"): col`colnum'	

 loc ++colnum


*** Column 7: County-level unemployment

reg updating shock shock_lowcountyunemp highunemp_rate3y prior prior_lowcountyunemp $controls, r

sigstar shock, prec(3)
estadd loc thisstat2 = "`r(bstar)'": col`colnum'
estadd loc thisstat3 = "`r(sestar)'": col`colnum'

sigstar shock_lowcountyunemp, prec(3)
estadd loc thisstat23 = "`r(bstar)'": col`colnum'
estadd loc thisstat24 = "`r(sestar)'": col`colnum'

test 	shock + shock_lowcountyunemp = 0
estadd loc thisstat29 = string(r(p), "%9.3f"): col`colnum'

qui sum updating if highunemp_rate3y!=.
estadd loc thisstat31 = r(N): col`colnum'
*estadd loc thisstat29 = string(r2[1,1], "%9.2f"): col`colnum'	

 loc ++colnum


*** Column 8: financial literacy.

reg updating shock shock_finlit_index finlit_index prior prior_finlit_index $controls, r

sigstar shock, prec(3)
estadd loc thisstat2 = "`r(bstar)'": col`colnum'
estadd loc thisstat3 = "`r(sestar)'": col`colnum'

sigstar shock_finlit_index, prec(3)
estadd loc thisstat26 = "`r(bstar)'": col`colnum'
estadd loc thisstat27 = "`r(sestar)'": col`colnum'

test 	shock + shock_finlit_index = 0
estadd loc thisstat29 = string(r(p), "%9.3f"): col`colnum'

qui sum updating if shock_finlit_index!=.
estadd loc thisstat31 = r(N): col`colnum'

 



loc rowlabels " " " "Shock (a)" " " " " "Shock $\times$ (b) " "High education" " " "Shock $\times$ (b) " "High earnings" " " "Shock $\times$ (b) " "Age$>$44" " " "Shock $\times$ (b) " "Female" " " "Shock $\times$ (b) " "Non-cyclical industry" " " "Shock $\times$ (b) " "Never unemployed"   " " "Shock $\times$ (b) " "Low county unemployment" " " "Shock $\times$ (b) " "High financial literacy" " " "Pr(a+b)=0" " " "Observations" " " "\hline" " "   "

loc rowstats ""
loc rowstats ""

forval i = 1/31 {
loc rowstats "`rowstats' thisstat`i'"
}

esttab * using "learningrate_het_interact.tex", replace cells(none) booktabs nonotes nomtitles compress alignment(c) nogap noobs nobaselevels label stats(`rowstats', labels(`rowlabels')) ///
mgroups("Updating"  , pattern(1 0 0 0 0 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

eststo clear	





















